use crate::hystrix::metriccollector::default::DefaultMetricCollector;
use crate::hystrix::metrics::MetricCollector;

pub struct MetricCollectorRegistry {
    registry:Vec<fn(name:String)->Box<dyn MetricCollector>>,
}

impl MetricCollectorRegistry {
    pub fn new() -> Self {
        let f = |name:String| -> Box<dyn MetricCollector> {
            Box::new(DefaultMetricCollector::default())
        };
        MetricCollectorRegistry{
            registry: vec![f]
        }
    }

    pub fn init(&mut self,name:String) -> Vec<Box<dyn MetricCollector>> {
        let mut metrics = Vec::new();
        for i in self.registry.clone() {
            metrics.push(i(name.clone()));
        }

        metrics
    }

    pub fn register(&mut self,init:fn(name:String)->Box<dyn MetricCollector>) {
        self.registry.push(init);
    }
}

